<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title><%= controller.action_name == 'run' ? @page.title : controller.action_name %></title>
  <%= stylesheet_link_tag 'jsspec' %>
  <%= stylesheet_link_tag 'scaffold' %>
  <%= stylesheet_link_tag 'xq_ui' %>
  <%= javascript_include_tag :defaults %>
  <%= javascript_include_tag 'jester' %>
  <%= javascript_include_tag 'gears_init' %>
  <%= javascript_include_tag 'extension' %>
  <%= javascript_include_tag 'jsspec' %>
  <%= javascript_include_tag 'diff_match_patch' %>
  <%= javascript_include_tag 'sproutcore' %>
  <%= javascript_include_tag 'xquared' %>
<%= yield :header -%>
</head>
<body>
<%
offline_id = []
if(params[:offline_id].nil? == false)
	offline_id = params[:offline_id]
end
%>
<script>

function syncAndGo() {
// Sync
var Page = new Base("Page", "http://anarch.re.kr:3000", "page", "pages");


//initDB
 try {
    db = google.gears.factory.create('beta.database', '1.0');
  } catch (ex) {
    //setError('Could not create database: ' + ex.message);
    alert("Could not create datevase: "+ ex.message);
  }
  
  if (db) {
    db.open('springnote');
    db.execute('drop table Page');
    db.execute('create table if not exists Page' +
               ' (identifier integer primary key, title varchar(255), source text)');
    db.execute('delete from Page');
    
    <%
    	for __id in offline_id
    %> 
    	var page = Page.find(<%= __id %>);    
    	db.execute("insert into Page values(" + page.identifier + ",'" + page.title + "','" + page.source + "')");
    <%
    	end
    %>
  }

// Insert into DB
alert(page.source);
// Go
window.location = "/page.html";
}
</script>
<p><a href="http://webcode.springnote.com">Web Code Documentation</a></p>
<!--
<p><a href="javascript:syncAndGo()">Go offline</a></p>
-->
<p style="color: green"><%= flash[:notice] %></p>
<p style="text-align: right"><%= link_to 'Home', {:controller => 'pages', :action => 'index'} %> | <%= link_to 'Log out', {:controller => 'auth', :action => 'logout'} %></p>
<%= yield  %>

</body>
</html>
